<?php
/**
 * +---------------------------------------------------
 * @File: CommonAction.class.php
 * @Function: 
 * @Date: 2011-6-1
 * @Author: Jackean <mosquitoyuan@163.com>
 * @Version: 
 * +---------------------------------------------------
 */
 
 class CommonAction extends Action
 {
 	function _initialize()
 	{
 		header("Content-Type:text/html; charset=utf-8");
 		
 		if (C('USER_AUTH_ON') && !in_array(ACTION_NAME, explode(',', C('NOT_AUTH_ACTION'))))
		{
			import('@.ORG.IIARBAC');
			if (!IIARBAC::AccessDecision())
			{
				//检查认证识别号，为假跳转到认证网管
				if (!$_SESSION [C ( 'USER_AUTH_KEY' )]) redirect ( PHP_FILE . C ( 'USER_AUTH_GATEWAY' ) ); 
				// 没有权限 抛出错误
				if (C ( 'RBAC_ERROR_PAGE' )) {
					// 定义权限错误页面
					redirect ( C ( 'RBAC_ERROR_PAGE' ) );
				} else {
					// 提示错误信息
					$this->error ( L ( '_VALID_ACCESS_' ) );
				}
			}
		}
		
		//基于用户信息的实时认证
		if (C('USER_AUTH_TYPE') == 2)
		{
			
		}
		
		//超时为动作弹出
		if (C('TIME_LOGOUT_ON'))
		{
			
		}
 	}
 	
 	/**
 	 * +-------------------------------------------------
 	 * @ 获取用户的角色组
 	 * +-------------------------------------------------
 	 * @ $type: 1,获取用户的角色ID; 2,获取用的角色名称
 	 * @ $uid：   为空时查询当前登录用户的角色信息
 	 * +-------------------------------------------------
 	 */
 	protected function getUserRole($type=1,$uid='')
 	{
 		$uid = $uid ? intval($uid) : $_SESSION[C('USER_AUTH_KEY')];
 		$rid = M(C('RBAC_USER_TABLE'))->where("`u_id`=$uid")->getField('r_id');
 		$rname = M(C('RBAC_ROLE_TABLE'))->where("`id`=$rid")->getField('name');
 		if ($type == 1)
 		{
 			return $rid;
 		}else if($type == 2){
 			return $rname;
 		}else {
 			return array($rid,$rname);
 		}
 	}
 	
 	/**
 	 * +-------------------------------------------------
 	 * @ 获取角色的菜单组权限
 	 * +-------------------------------------------------
 	 */
 	protected function getManageNavG($rid)
 	{
 		$re = M('RoleMnav')->where("`r_id`=$rid")->getField('nav_id');
 		return explode(',',$re);
 	}
 	
 	/**
 	 * +-------------------------------------------------
 	 * @ 获取登录用户的信息
 	 * +-------------------------------------------------
 	 */
 	protected function getLoginUserInfo()
 	{
 		$uid = intval($_SESSION[C('USER_AUTH_KEY')]);
 		$data = M(C('USER_AUTH_MODEL'))->where("`id`=$uid")->find();
 		unset($data['password']);
 		return $data;
 	}
 	
 	/**
 	 * +-----------------------------------------------
 	 * @ 获取后台菜单组
 	 * +-----------------------------------------------
 	 */
 	public function getmannavgroup($status=0,$outtype=0)
 	{
 		$Form = M('Manav');	
 		$list = '';
 		if ($status == 0) $list = $Form->select();
 		$list = $Form->where('`status`=1')->select();
 		if ($outtype == 0) return $list;
 		foreach ($list as $val)
 		{
 			$list['navlist'][$val['id']] = $val['name'];
 		}
 		return $list['navlist'];
 	}
 }
 ?>